package com.bsoft.config;


import com.bsoft.pojo.Demo01Message;
import com.bsoft.pojo.Fanout.Demo03Message;
import com.bsoft.pojo.Topic.Demo02Message;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    //直连交互机

    public static class DirectExchangeDemoConfiguration {
        @Bean
        //创建Queue
        public Queue demo01QUeue() {
            return new Queue(Demo01Message.QUEUE, true, false, false);
        }

        //创建Direct Exchange
        @Bean
        public DirectExchange demo01Exchanges() {
            return new DirectExchange(Demo01Message.EXCHANGE, true, false);

        }

        @Bean
        public Binding demo01Bingding() {
            return BindingBuilder.bind(demo01QUeue()).to(demo01Exchanges()).with(Demo01Message.ROUTING_KEY);
        }

        //topic
        //创建Queue
        @Bean
        public Queue demo02Queue() {
            return new Queue(Demo02Message.QUEUE,
                    true, false, false
            );
        }

        //创建topic Exchenge
        @Bean
        public TopicExchange demo02Exchange() {
            return new TopicExchange(Demo02Message.EXCHANGE,
                    true, false
            );
        }

        @Bean
        public Binding demo02Binding() {
            return BindingBuilder.bind(demo02Queue()).to(demo02Exchange()).with(Demo02Message.ROUTING_KEY);

        }

        //Fanout 扇形
        @Bean
        public Queue demo03QueueA() {
            return new Queue(Demo03Message.QUEUE_A, //queue的名字
                    true,    //是否持久化
                    false,    //是否排它
                    false    //是否自动删除
            );
        }

        //创建QuenuB
        @Bean
        public Queue demo03QueueB() {
            return new Queue(Demo03Message.QUEUE_B,
                    true,  //是否持久化
                    false,     //是否排他
                    false      //是否删除

            );
        }

        //创建Fanout Exchange
        @Bean
        public FanoutExchange demo03Exchange() {
            return new FanoutExchange(Demo03Message.EXCHANGE,
                    true,  //是否持久化
                    false       // 是否排它
            );
        }

        //创建BingdA
        @Bean
        public Binding demo03BindBindingA() {
            return BindingBuilder.bind(demo03QueueA()).to(demo03Exchange());
        }

        //创建bingd B
        @Bean
        public Binding demo03BindBindingB() {
            return BindingBuilder.bind(demo03QueueB()).to(demo03Exchange());
        }

    }
}
